package com.szu.subject.ui.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.szu.subject.domains.Course;
import com.szu.subject.domains.Selection;
import com.szu.subject.domains.Student;
import com.szu.subject.ui.mapper.StudentMapper;
import com.szu.subject.ui.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentMapper studentMapper;
	@Override
	public Student getStudentByPK(Long id) {
		return studentMapper.getStudentByPK(id);
	}

	@Override
	public List<Course> getCourses(Long id) {
		return studentMapper.getCourses(id);
	}

	@Transactional
	@Override
	public int addCourse( Selection selection) {
		return studentMapper.insertCourses(selection);
	}

	@Transactional
	@Override
	public int removeCourse( Selection selection) {
		return studentMapper.deleteCourses(selection);
	}

	@Override
	public boolean isConflict(List<Long> timeId, Long newTimeId) {
		return timeId.contains(newTimeId);
	}

	@Transactional
	@Override
	public Student createStudent(Student student) {
		studentMapper.createStudent(student);
		return student;
	}

	@Transactional
	@Override
	public Student updateStudent(Student student) {
		studentMapper.updateStudent(student);
		return student;
	}

	@Transactional
	@Override
	public int deleteStudent(Long id) {
		return studentMapper.deleteStudent(id);
	}

	@Transactional
	@Override
	public List<Student> batchCreateStudents(List<Student> students) {
		studentMapper.batchCreateStudents(students);
		return students;
	}

	@Transactional
	@Override
	public List<Student> batchUpdateStudents(List<Student> students) {
		studentMapper.batchUpdateStudents(students);
		return students;
	}

	@Transactional
	@Override
	public int batchDeleteStudents(List<Long> ids) {
		return studentMapper.batchDeleteStudents(ids);
	}

	@Transactional
	@Override
	public Student getStudentByAccount(String account) {
		return studentMapper.getStudentByAccount(account);
	}

}
